﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace com.orange.examination
{
    public partial class WebForm17 : System.Web.UI.Page
    {
        private static int id;
        protected void Page_Load(object sender, EventArgs e)
        {
            if(Session["admin"]==null)
            {
               Response.Redirect("../LoginAndRegister/Login.aspx");
            }
            else if (!IsPostBack)
            {
                string sql = "select LessonName from tb_Lesson";
                DataSet ds = BaseClass.ExecDataSet(sql);
                this.ddlTKm.DataSource = ds.Tables[0];
                this.ddlTKm.DataTextField = "LessonName";//显示的列
                this.ddlTKm.DataBind();
                id = Convert.ToInt32(Request.QueryString["Tid"]);
                MySqlConnection conn = BaseClass.DBCon();
                conn.Open();
                MySqlCommand cmd = new MySqlCommand("select * from tb_Teacher where ID=" + id, conn);
                MySqlDataReader sdr = cmd.ExecuteReader();
                sdr.Read();
                txtTName.Text = sdr["TeacherName"].ToString();
                txtTNum.Text = sdr["TeacherNum"].ToString();
                txtTPwd.Text = sdr["TeacherPwd"].ToString();
                ddlTKm.SelectedValue= sdr["TeacherCourse"].ToString();
                sdr.Close();
                conn.Close();
            }
        }
        protected void btnSava_Click(object sender, EventArgs e)
        {
            id = Convert.ToInt32(Request.QueryString["Tid"]);
            if (txtTName.Text == "" || txtTPwd.Text == "")
            {
                Response.Write("<script>window.alert('请将信息填写完整！');</script>");
                return;
            }
            else
            {
                string sql = "update tb_Teacher set TeacherNum='"+ txtTNum.Text.Trim() + "',TeacherName='" + txtTName.Text.Trim() + "',TeacherPwd='" + txtTPwd.Text.Trim() + "',TeacherCourse='" + ddlTKm.SelectedValue.ToString() + "'  where id='" + id + "'";
                BaseClass.OperateData(sql);
                Response.Write("<script>window.alert('修改成功！');location.href='TeacherInfo.aspx';</script>");
            }
        }

        protected void btnConcel_Click(object sender, EventArgs e)
        {
            Response.Redirect("TeacherInfo.aspx");
        }
    }
}